import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

import javax.swing.*;

public class WindownMain extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Dimension sreen=Toolkit.getDefaultToolkit().getScreenSize();
	JButton ok;
	JButton cancle;
	JButton apply;
	PropertiesEx pro;
	JButton propertices;
	JPanel pan1;
	JPanel pn;
	public WindownMain() {
		UIManager.LookAndFeelInfo look[]=UIManager.getInstalledLookAndFeels();
		try{
			UIManager.setLookAndFeel(look[3].getClassName());
		}catch(Exception e){
			
		}
		pro=new PropertiesEx();
		setTitle("sound");
		setResizable(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setLocation((sreen.width-getWidth())/4, (sreen.height-getHeight())/4);
		setSize(410, 460);
		setIconImage(Toolkit.getDefaultToolkit().getImage("images/Apps-krfb-icon.png"));
		createTabs();
	}

 
	public static void main(String[] args) {
		WindownMain main=new WindownMain();
		main.setVisible(true);
	}
	
	void createTabs(){
		JPanel pn1=new JPanel();
		pn1.setLayout(new BoxLayout(pn1, BoxLayout.Y_AXIS));
		pn1.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
		add(pn1);
		
		JPanel pnbottom=new JPanel();
		pnbottom.setLayout(new FlowLayout(FlowLayout.RIGHT,5,5));
		pnbottom.setBorder(BorderFactory.createEmptyBorder(1, 5, 0, -5));
		ok=new JButton("OK");
		pnbottom.add(ok);
		ok.add(Box.createRigidArea(new Dimension(40, 15)));
		cancle=new JButton("Cancle");
		pnbottom.add(cancle);
		cancle.add(Box.createRigidArea(new Dimension(40, 15)));
		apply=new JButton("Apply");
		pnbottom.add(apply);
		apply.add(Box.createRigidArea(new Dimension(40, 15)));
		
	
		JTabbedPane tap=new JTabbedPane();
		tap.setPreferredSize(new Dimension(410, 490));
		tap.addTab("Playback", createTabPlayback());
		tap.addTab("Recording", createTabRecording());
		tap.addTab("Playback", createTabSound());
		tap.addTab("Communications", createTabCommunications());
		
		pn1.add(tap);
		pn1.add(pnbottom);
	}
	JPanel createTabPlayback(){
		JPanel playbackpn=new JPanel();
		playbackpn.setLayout(new BoxLayout(playbackpn, BoxLayout.Y_AXIS));
		
		JPanel toppn=new JPanel(new FlowLayout(FlowLayout.LEFT,10,0));
		JLabel lb=new JLabel("Select a playback device below to modify its settings");
		lb.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10));
		toppn.add(lb);
		playbackpn.add(toppn);
		
		JPanel center=new JPanel(new BorderLayout());
		center.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
		
		JPanel pane=new JPanel();
		pane.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		pane.setBorder(BorderFactory.createEtchedBorder());
		
		pan1=new JPanel();
		pan1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		pan1.setBorder(BorderFactory.createEtchedBorder());
		pan1.setPreferredSize(new Dimension(354, 60));
		
		JLabel lb1=new JLabel(new ImageIcon("images/Apps-digikam-icon.png"));
		lb1.setPreferredSize(new Dimension(80, 50));
		pan1.add(lb1);
		
		pn=new JPanel();
		pn.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		pn.setPreferredSize(new Dimension(200, 40));
		JLabel lb2=new JLabel("Digital Audio (S/PDIF)");
		JLabel lb3=new JLabel("Hight Definition Audio Device");
		lb3.setEnabled(false);
		JLabel lb4=new JLabel("Default Device");
		lb4.setEnabled(false);
		pn.add(lb2);
		pn.add(lb3);
		pn.add(lb4);
		pan1.add(pn);
		pan1.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				propertices.setEnabled(true);
				pan1.setBackground(Color.CYAN);
				pn.setBackground(Color.CYAN);
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				pan1.setBackground(null);
				pn.setBackground(null);
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				pan1.setBackground(Color.CYAN);
				pn.setBackground(Color.CYAN);
			}
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
			}
		});
		
		pane.add(pan1);
		center.add(pane);
		playbackpn.add(center);
		
		JPanel bottompn=new JPanel();
		bottompn.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
		JButton configure=new JButton("Configure");
		configure.add(Box.createRigidArea(new Dimension(55, 15)));
		configure.setEnabled(false);
		bottompn.add(configure);
		JLabel trunggian=new JLabel();
		trunggian.setPreferredSize(new Dimension(10, 0));
		bottompn.add(trunggian);
		JComboBox<Object> com=new JComboBox<Object>();
		com.setPreferredSize(new Dimension(110, 25));
		com.setEnabled(false);
		bottompn.add(com);
		propertices=new JButton("Propertices");
		propertices.setEnabled(false);
		propertices.add(Box.createRigidArea(new Dimension(75, 15)));
		propertices.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				pro.setVisible(true);
			}
		});
		bottompn.add(propertices);
		playbackpn.add(bottompn);
		
		return playbackpn;
	}
	JPanel createTabRecording(){
		JPanel recordingpn=new JPanel();
		recordingpn.setLayout(new BoxLayout(recordingpn, BoxLayout.Y_AXIS));
		
		JPanel toppn=new JPanel(new FlowLayout(FlowLayout.LEFT,10,0));
		JLabel lb=new JLabel("Select a recording device below to modify its settings");
		lb.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10));
		toppn.add(lb);
		recordingpn.add(toppn);
		
		JPanel center=new JPanel(new BorderLayout());
		center.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
		
		JPanel pane=new JPanel();
		pane.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		pane.setBorder(BorderFactory.createEtchedBorder());

		center.add(pane);
		recordingpn.add(center);
		
		JPanel bottompn=new JPanel();
		bottompn.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
		JButton configure=new JButton("Configure");
		configure.add(Box.createRigidArea(new Dimension(55, 15)));
		configure.setEnabled(false);
		bottompn.add(configure);
		JLabel trunggian=new JLabel();
		trunggian.setPreferredSize(new Dimension(10, 0));
		bottompn.add(trunggian);
		JComboBox<Object> com=new JComboBox<Object>();
		com.setPreferredSize(new Dimension(110, 25));
		com.setEnabled(false);
		bottompn.add(com);
		JButton propertices=new JButton("Propertices");
		propertices.add(Box.createRigidArea(new Dimension(75, 15)));
		bottompn.add(propertices);
		recordingpn.add(bottompn);
		
		return recordingpn;
	}
	JPanel createTabSound(){
		JPanel playbackpn=new JPanel();
		playbackpn.setLayout(new BoxLayout(playbackpn, BoxLayout.Y_AXIS));
		
		JPanel pn1=new JPanel();
		pn1.setLayout(new FlowLayout(FlowLayout.LEFT));
		pn1.setBorder(BorderFactory.createEmptyBorder(10, 20, 0, 0));
		String text="A sound theme is a set of sounds applied to events in Windowns " ;
		String text1="and programs. You can select an existing scheme or save one you" ;
		String text2="have modified";
		JLabel lb1=new JLabel(text);
		lb1.setPreferredSize(new Dimension(410, 10));
		JLabel lb2=new JLabel(text1);
		lb2.setPreferredSize(new Dimension(410, 10));
		JLabel lb3=new JLabel(text2);
		lb3.setPreferredSize(new Dimension(410, 10));
		pn1.add(lb1);
		pn1.add(lb2);
		pn1.add(lb3);
		
		JLabel lncen=new JLabel("Sound Scheme:");
		lncen.setPreferredSize(new Dimension(410, 10));
		pn1.add(lncen);
		playbackpn.add(pn1);
		
		JPanel pncen=new JPanel();
		pncen.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		
		String[] list={"Quirky","Afternoon","Dalta"};
		JComboBox<String> com1 =new JComboBox<String>(list);
		com1.setPreferredSize(new Dimension(150, 20));
		com1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
		pncen.add(com1);
		JPanel pnr=new JPanel();
		pnr.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton saveas=new JButton("Save As..");
		saveas.add(Box.createRigidArea(new Dimension(50, 15)));
		pnr.add(saveas);
		JButton delete=new JButton("Delete");
		delete.add(Box.createRigidArea(new Dimension(50, 15)));
		pnr.add(delete);
		pncen.add(pnr);
		pn1.add(pncen);

		String txt="To change sounds,ckick a program event in the folowing list and" ;
		String txt1="then select a sound to apply.You can save the changes as a new" ;
		String txt2="sound scheme.";
		JLabel lb4=new JLabel(txt);
		lb4.setPreferredSize(new Dimension(410, 10));
		JLabel lb5=new JLabel(txt1);
		lb5.setPreferredSize(new Dimension(410, 10));
		JLabel lb6=new JLabel(txt2);
		lb6.setPreferredSize(new Dimension(410, 10));
		pn1.add(lb4);
		pn1.add(lb5);
		pn1.add(lb6);

		JLabel lncen1=new JLabel("Program Events:");
		lncen1.setPreferredSize(new Dimension(410, 15));
		pn1.add(lncen1);
		
		Vector<String> v1=new TreeNodeVector<>("Windown", new String[]{"Asterisk","Critical Battery Alarm","Critical Stop"});
		Vector<String> v2=new TreeNodeVector<>("Windown Explorer", new String[]{"Fax error","Fax sent","Incoming call"});
		Vector<String> v3=new TreeNodeVector<>("Windown Speech Recoginition", new String[]{"Off","On","Sleep"});
		Object root[]={v1,v2,v3};
		Vector<Object>rootVector= new TreeNodeVector<>("Root", root);
		
		JPanel pntree=new JPanel();
		pntree.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		pntree.setPreferredSize(new Dimension(320, 95));
		pntree.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0));
		JTree tree=new JTree(rootVector);
		JScrollPane scrollpane=new JScrollPane(tree);
		scrollpane.setPreferredSize(new Dimension(320, 95));
		pntree.add(scrollpane);
		pn1.add(pntree);
		
		JPanel pncheck=new JPanel();
		pncheck.setPreferredSize(new Dimension(410, 18));
		pncheck.setLayout(new FlowLayout(FlowLayout.LEFT,-4,0));
		JCheckBox check=new JCheckBox("Play Windowns Startup sound");
		pncheck.add(check);
		pn1.add(pncheck);
		
		JPanel pnbottom=new JPanel();
		pnbottom.setPreferredSize(new Dimension(410, 15));
		JLabel lncen2=new JLabel("Sounds:");
		lncen2.setEnabled(false);
		lncen2.setPreferredSize(new Dimension(410, 10));
		pnbottom.add(lncen2);
		pn1.add(pnbottom);
		
		JPanel pncen1=new JPanel();
		pncen1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		JComboBox<Object> com2 =new JComboBox<Object>(new String []{"Quirky","Afternoon","Dalta"});
		com2.setPreferredSize(new Dimension(150, 20));
		com2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		pncen1.add(com2);
		JPanel pnr1=new JPanel();
		pnr1.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton test=new JButton("Test");
		test.add(Box.createRigidArea(new Dimension(50, 15)));
		pnr1.add(test);
		JButton browse=new JButton("Browse");
		browse.add(Box.createRigidArea(new Dimension(50, 15)));
		test.setEnabled(false);
		browse.setEnabled(false);
		com2.setEnabled(false);
		pnr1.add(browse);
		pncen1.add(pnr1);
		pn1.add(pncen1);
		
		return playbackpn;
	}
	JRadioButton[] check=new JRadioButton[4];
	JPanel createTabCommunications(){
		String text;
		String text1;
		String text2;
		JPanel communicationspn=new JPanel();
		communicationspn.setLayout(new BoxLayout(communicationspn, BoxLayout.Y_AXIS));
		text="Windown can automatically adjust the volume of different" ;
		text1="sound when you are using your PC to place or receive" ;
		text2=	"telephone calls";
		JPanel pn1=new JPanel();
		communicationspn.add(pn1);
		pn1.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
		JLabel lb=new JLabel(new ImageIcon("images/Apps-digikam-icon.png"));
		lb.setPreferredSize(new Dimension(50, 50));
		pn1.add(lb);
		JLabel lb1=new JLabel(text);
		JLabel lb2=new JLabel(text1);
		JLabel lb3=new JLabel(text2);
		JPanel pn2=new JPanel(new GridLayout(3,1));
		pn2.setPreferredSize(new Dimension(295, 50));
		pn2.add(lb1);
		pn2.add(lb2);
		pn2.add(lb3);
		pn1.add(pn2);
		JPanel pn3=new JPanel();
		pn3.setLayout(new FlowLayout(FlowLayout.LEFT,10,0));
		JLabel lb4=new JLabel("When Windown detects communication activity:");
		lb4.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
		pn3.add(lb4);
		pn1.add(pn3);
		ButtonGroup group=new ButtonGroup();
		check[0]=new JRadioButton("Mute all other sounds");
		check[1]=new JRadioButton("Reduce the volume of other sound by 80%");
		check[2]=new JRadioButton("Reduce the volume of other sound by 50%");
		check[3]=new JRadioButton("Do nothing");
		group.add(check[0]);
		group.add(check[1]);
		group.add(check[2]);
		group.add(check[3]);
		JPanel pn5=new JPanel();
		pn5.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
		pn5.setLayout(new BoxLayout(pn5, BoxLayout.Y_AXIS));
		pn5.add(check[0]);
		pn5.add(check[1]);
		pn5.add(check[2]);
		pn5.add(check[3]);
		pn1.add(pn5);
		return communicationspn;
	}
}
	class TreeNodeVector<E> extends Vector<E> {
		  /**
			 * 
			 */
		private static final long serialVersionUID = 1L;
		String name;
		  TreeNodeVector(String name) {
		    this.name = name;
		  }
		  TreeNodeVector(String name, E elements[]) {
		    this.name = name;
		    for (int i = 0, n = elements.length; i < n; i++) {
		      add(elements[i]);
		    }
		  }
		  public String toString() {
		    return "[" + name + "]";
		  }
}
